package com.dxb.idmr.controller;


import com.dxb.idmr.entity.Questions;
import com.dxb.idmr.service.IQuestionsService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;

/**
 * <p>
 * 问题表 前端控制器
 * </p>
 *
 * @author dxb
 * @since 2020-05-01
 */
@RestController
@RequestMapping("/questions")
public class QuestionsController {
    @Autowired
    IQuestionsService questionsService;

    @RequestMapping(method = RequestMethod.POST)
    @ApiOperation(value = "增")
    public String add(Questions questions) {
        if (questionsService.save(questions)) {
            return "ok";
        }
        return "!ok";
    }

    @RequestMapping(method = RequestMethod.PUT, value = "/{id}")
    @ApiOperation(value = "改")
    public String update(Questions questions, @PathParam("id") String id) {
        return "ok";
    }

    @RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
    @ApiOperation(value = "删")
    public String delete(@PathParam("id") String id) {
        return "ok";
    }

    @RequestMapping(method = RequestMethod.GET)
    @ApiOperation(value = "查")
    public Questions get(@ApiParam(value = "问题ID", required = true) @RequestParam(required = true) String questionId) {
        return questionsService.getById(questionId);
    }
}
